<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增入库管理')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-stockEnter-add">
            <input name="storageId" type="hidden" id="storageId" >
        	<h4 class="form-header h4">入库信息</h4>
            <div class="row">            
                <div class="col-sm-6">  
		            <div class="form-group">
		                <label class="col-sm-4 control-label is-required">标题：</label>
		                <div class="col-sm-8">
		                    <input name="title" class="form-control" type="text" maxlength=50 required>
	                	</div>   	
		            </div> 
                </div>            	           
                <div class="col-sm-6">   
		             <div class="form-group">    
		                <label class="col-sm-4 control-label is-required">仓库：</label>
		                <div class="col-sm-8">
		                	<div class="input-group">
			                    <input name="storageName" onclick="selectStorage()" id="storageName" type="text" placeholder="请选择仓库 " class="form-control" required readonly>
			                	<span class="input-group-addon"><i class="fa fa-search"></i></span>
							</div>
		                </div>
		            </div>
                </div>
            </div>
            
            <div class="row">
                <div class="col-sm-6">
		            <div class="form-group">    
		                <label class="col-sm-4 control-label is-required">入库日期：</label>
		                <div class="col-sm-8">
		                    <div class="input-group date">
		                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
		                        <input name="enterDate" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
		                    </div>
		                </div>
		            </div>
                </div>
                <div class="col-sm-6">
		            <div class="form-group">    
		                <label class="col-sm-4 control-label is-required">负责人：</label>
		                <div class="col-sm-8">                
		                    <div class="input-group">
			                    <input name="enterBy" onclick="selectUser()" id="enterBy" type="text" placeholder="请选择负责人" class="form-control" required readonly>
			                	<span class="input-group-addon"><i class="fa fa-search"></i></span>
							</div>
		                </div>
		            </div>
                </div>
            </div>
            
            <h4 class="form-header h4">产品信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-success btn-sm" onclick="addColumn()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-danger btn-sm" onclick="sub.delColumn()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
					    <table id="bootstrap-table"></table>
					</div>
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "crm/stockEnter"
        $("#form-stockEnter-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
            	var data = $("#form-stockEnter-add").serializeArray();  
                $.operate.saveTab(prefix + "/add", data);
            }
        }

        $("input[name='enterDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        
        $(function() {
		    var options = {
			    height: $(window).height()/2,
                pagination: false,
		        showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
		        columns: [{
		            checkbox: true
		        },
		        {
		        	field: 'index',
		        	align: 'center',
		        	title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
		        {
		            field: 'productId',
		            align: 'center',
		            title: '产品ID',
		            width:40,
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input class='form-control' type='text' name='products[%s].productId' id='productId_%s' value='%s' readonly required>", index, index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'productName',
		            align: 'center',
		            title: '产品名称',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input class='form-control' type='text' placeholder='请选择产品' onclick='selectStockEnterProduct(" + index + ")' name='products[%s].productName' id='productName_%s' value='%s' required>", index, index, value);
		        		return html;
                    }
		        },
		        {
		            field: 'productNum1',
		            align: 'center',
		            title: '入库数量',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input class='form-control' type='number' min=1 name='products[%s].productNum1' value='%s' required>", index, value);
		        		return html;
                    }
		        }]
		    };
		    $.table.init(options);
		});
        
        function addColumn() {
        	var count = $("#" + table.options.id).bootstrapTable('getData').length;
        	sub.editColumn();
        	
        	$("#" + table.options.id).bootstrapTable('insertRow', {
        		index: count,
                row: {
                	index: $.table.serialNumber(count),
                	productId:"",
                	productName: "",
                	productNum1: ""
                }
        	});
        }

        /*  选择仓库 */
        function selectStorage() {
        	 var url = ctx + "crm/storage/selectStorage";
        	 $.modal.open("选择仓库", url);
        }

        /* 选择用户 */
        function selectUser() {
        	var url = ctx + 'system/user/selectUser';
        	$.modal.open("选择人员", url);
        }
        
		// 选择入库产品
		function selectStockEnterProduct(columnId) {
        	var url = ctx + "crm/product/selectStockEnterProduct/" + columnId;
			 $.modal.open("选择入库产品", url);
		}
    </script>
</body>
</html>